<template>
  <div class="container-content">
    <el-row :gutter="15">
      <el-form
        ref="elForm"
        :model="formData"
        :rules="rules"
        size="small"
        label-width="100px"
      >
        <el-col :span="12">
          <el-row :gutter="15">
            <el-col :span="24">
              <el-form-item
                label-width="200px"
                label="币别"
                prop="kingBaseCurrencyId"
              >
                <el-select
                  v-model="formData.kingBaseCurrencyId"
                  placeholder="请选择币别"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in kingBaseCurrencyIdOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item
                label-width="200px"
                label="退票日期"
                prop="createTime"
              >
                <el-date-picker
                  v-model="formData.createTime"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  :style="{ width: '100%' }"
                  placeholder="请选择退票日期"
                  clearable
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item
                label-width="200px"
                label="往来单位类型"
                prop="transactionCompanyType"
              >
                <el-select
                  v-model="formData.transactionCompanyType"
                  placeholder="请选择往来单位类型"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in transactionCompanyTypeOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item
                label-width="200px"
                label="数据状态"
                prop="dataStatus"
              >
                <el-select
                  v-model="formData.dataStatus"
                  placeholder="请选择数据状态"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in dataStatusOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label-width="160px" label="汇率" prop="rate">
                <el-input
                  v-model="formData.rate"
                  placeholder="请输入汇率"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="12">
          <el-row :gutter="15">
            <el-col :span="24">
              <el-form-item
                label-width="200px"
                label="票据类型"
                prop="billType"
              >
                <el-select
                  v-model="formData.billType"
                  placeholder="请选择票据类型"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in billTypeOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item
                label-width="200px"
                label="退票金额	"
                prop="faceAmount"
              >
                <el-input
                  v-model="formData.faceAmount"
                  placeholder="请输入票面金额	"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item
                label-width="200px"
                label="往来单位"
                prop="transactionCompanyId"
              >
                <el-select
                  v-model="formData.transactionCompanyId"
                  placeholder="请选择往来单位"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in transactionCompanyIdOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item
                label-width="160px"
                label="汇率类型"
                prop="rateType"
              >
                <el-input
                  v-model="formData.rateType"
                  placeholder="请输入汇率类型"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import { editRefund, getDetail } from "@/api/finance/receivebill";
export default {
  props: ["rowId"],
  data() {
    return {
      formData: {
        actualMoney: "",
        baseCurrencyId: "",
        billNo: "",
        billSerialNo: "",
        billType: "",
        bondAccount: "",
        bondPayMoney: "",
        costMoney: "",
        createBy: "",
        createTime: "",
        currentPayFaceMoney: "",
        dataStatus: "",
        docTypeCode: "",
        faceMoney: "",
        generalAccount: "",
        generalPayMoney: "",
        id: "",
        interest: "",

        ownBaseCurrencyId: "",
        params: {},
        payBankId: "",
        payBillId: "",
        payDeptId: "",
        payId: "",
        payTime: "",
        rate: "",
        rateType: "",
        remark: "",
        remarks: "",
        searchValue: "",
        settlementNo: "",
        sourceNo: "",
        sourceType: "",
        transactionCompanyId: "",
        transactionCompanyType: "",
        unpaidFaceMoney: "",
        updateBy: "",
        updateTime: "",
      },
      rules: {
        faceRate: [
          {
            required: true,
            message: "请输入票面利率",
            trigger: "blur",
          },
        ],
        kingBaseCurrencyId: [
          {
            required: true,
            message: "请选择币别",
            trigger: "change",
          },
        ],

        receiptBank: [
          {
            required: true,
            message: "请输入收款银行",
            trigger: "blur",
          },
        ],
        receiptBankAddress: [
          {
            required: true,
            message: "请输入收款银行地址",
            trigger: "blur",
          },
        ],
        receiptDeptId: [
          {
            required: true,
            message: "请输入收款单位Id",
            trigger: "blur",
          },
        ],
        billSerialNo: [
          {
            required: true,
            message: "请输入票据流水号",
            trigger: "blur",
          },
        ],

        faceAmount: [
          {
            required: true,
            message: "请输入票面金额	",
            trigger: "blur",
          },
        ],
        payBankAccount: [
          {
            required: true,
            message: "请输入付款银行账号",
            trigger: "blur",
          },
        ],
        payBankId: [
          {
            required: true,
            message: "请输入付款银行Id",
            trigger: "blur",
          },
        ],

        receiptBankAccount: [
          {
            required: true,
            message: "请输入收款银行账号",
            trigger: "blur",
          },
        ],
        receiptBankName: [
          {
            required: true,
            message: "请输入收款银行名称",
            trigger: "blur",
          },
        ],
        receiptDeptType: [
          {
            required: true,
            message: "请选择付款单位类型",
            trigger: "change",
          },
        ],

        actualMoney: [
          {
            required: true,
            message: "请输入实付金额",
            trigger: "blur",
          },
        ],
        bondPayMoney: [
          {
            required: true,
            message: "请输入保证金账户支付金额",
            trigger: "blur",
          },
        ],
        currentPayFaceMoney: [
          {
            required: true,
            message: "请输入本次付款票面金额",
            trigger: "blur",
          },
        ],
        generalPayMoney: [
          {
            required: true,
            message: "请输入一般账户支付金额",
            trigger: "blur",
          },
        ],
        settlementNo: [
          {
            required: true,
            message: "请输入	结算号",
            trigger: "blur",
          },
        ],
        sourceType: [
          {
            required: true,
            message: "请输入源单类型",
            trigger: "blur",
          },
        ],
        transactionCompanyType: [
          {
            required: true,
            message: "请选择往来单位类型",
            trigger: "change",
          },
        ],
        bondAccount: [
          {
            required: true,
            message: "请选择保证金账号",
            trigger: "change",
          },
        ],
        costMoney: [
          {
            required: true,
            message: "请输入费用",
            trigger: "blur",
          },
        ],
        unpaidFaceMoney: [
          {
            required: true,
            message: "请输入未付款票面金额",
            trigger: "blur",
          },
        ],
        generalAccount: [
          {
            required: true,
            message: "请输入一般存款账号",
            trigger: "blur",
          },
        ],
        interest: [
          {
            required: true,
            message: "请输入利息",
            trigger: "blur",
          },
        ],
        sourceNo: [
          {
            required: true,
            message: "请输入源单单号",
            trigger: "blur",
          },
        ],
        transactionCompanyId: [
          {
            required: true,
            message: "请选择往来单位",
            trigger: "change",
          },
        ],
        remark: [],
      },
      billTypeOptions: [
        {
          label: "test",
          value: 1,
        },
      ],
      kingBaseCurrencyIdOptions: [],
      dataStatusOptions: [
        {
          label: "创建",
          value: 1,
        },
        {
          label: "审核中",
          value: 2,
        },
        {
          label: "已审核",
          value: 3,
        },
      ],
      receiptDeptTypeOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      settlementStatusOptions: [
        {
          label: "为空",
          value: 1,
        },
        {
          label: "到期付款",
          value: 2,
        },
        {
          label: "退票",
          value: 3,
        },
      ],
      acceptanceBankIdOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      transactionCompanyTypeOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      bondAccountOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      transactionCompanyIdOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
    };
  },
  methods: {
    submit(cb) {
      this.$refs["elForm"].validate((valid) => {
        if (!valid) return;
        // TODO 提交表单
        editRefund(this.formData).then((res) => {
          if (res.code === 200) {
            this.$message({
              message: "操作成功！",
              type: "success",
            });
            cb();
          }
        });
      });
    },
  },
  mounted() {
    this.getDicts("king_currency_type").then((res) => {
      this.kingBaseCurrencyIdOptions = res.data.map((item) => {
        return {
          label: item.dictLabel,
          value: item.dictValue,
        };
      });
    });
    if (this.rowId) {
      getDetail(this.rowId).then((res) => {
        if (res.code === 200) {
          this.formData = {
            ...this.formData,
            ...res.data.kingFinancePayBillEntity,
          };
        }
      });
    }
  },
};
</script>
<style lang="scss" scoped>
.divider {
  margin: 0;
}
</style>
